package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.InformBean;

import java.util.List;

/**
 * Created by Administrator on 2016/9/9 0009.
 */
public class InformAdapter extends BaseAdapter {
    private Context context;
    private List<InformBean> informList;

    public InformAdapter(Context context, List<InformBean> informList) {
        this.context = context;
        this.informList = informList;
    }

    @Override
    public int getCount() {
        return informList.size();
    }

    @Override
    public Object getItem(int position) {
        return informList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        InformViewHolder viewHolder = new InformViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.inform_item, null);
            viewHolder.iv_inform_pic = (ImageView) convertView.findViewById(R.id.iv_inform_pic);
            viewHolder.tv_inform_title = (TextView) convertView.findViewById(R.id.tv_inform_title);
            viewHolder.tv_inform_time = (TextView) convertView.findViewById(R.id.tv_inform_time);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (InformViewHolder) convertView.getTag();
        }

        if ("0".equals(informList.get(position).getImg())) {
            viewHolder.iv_inform_pic.setVisibility(View.GONE);
        }else {
            viewHolder.iv_inform_pic.setImageResource(Integer.parseInt(informList.get(position).getImg()));
        }
        viewHolder.tv_inform_title.setText(informList.get(position).getTitle());
        viewHolder.tv_inform_time.setText(informList.get(position).getTime());

        return convertView;
    }

    class InformViewHolder {
        ImageView iv_inform_pic;
        TextView tv_inform_title;
        TextView tv_inform_time;
    }
}
